home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c1.zip / ADDLF.C next >
Text File  |  1987-06-18  |  768b  |  27 lines

  1.  
  2. /* addlf -- copy input to output; add line-feeds only if necessary.
  3.  *          WHRauser   10-4-83             a better mouse trap.
  4.  */
  5. #include <stdio.h>         /* Microsoft C  Ver 1.04 */
  6.  
  7. #define  CR  0x000D        /* carriage return */
  8. #define  LF  0x000A        /* line feed */
  9. #define  TRUE     1
  10. #define  FALSE    0
  11.  
  12. main()      /* copy input to output and add line-feeds only if needed. */
  13. {
  14.     int  c;
  15.     int  addlf = FALSE;
  16.  
  17.     while ((c = getchar()) != EOF) {
  18.          if (addlf  &  c != LF) {
  19.               putchar(LF);
  20.               addlf = FALSE;
  21.          }
  22.          putchar(c);
  23.          if (c == CR)  addlf = TRUE;
  24.     }
  25. }
  26.  
  27.